<include file="Public:_head" />
<include file="Public:left" />
	<div id="neirong">
 		<!--<h2 class="lm_title">关联品牌</h2>-->
        <div id="GuanLian">
             <h3 class="subTitle"><img src="com_statics/images/icon_4.gif" alt="图片描述"/>关联品牌<span>设置品牌信息，求职可快速通过品牌名称找到工作岗位！</span></h3>
            <div id="GuanLianBrand">
                        <h3 class="NavTitle">已关联品牌</h3>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="GWlist">
							<volist name="brand.data" id="b">
                            <tr>
                                <td width="120">{$b.brand_name}</td>
                                <td ><a href=""><img src="{$b.brand_ico.url}" alt="图片描述" style="max-width:150px;max-height:70px;"/></a></td>
                                <td><eq name="b.brand_status" value="1">审核成功<else/><font color="red">等待审核..</font></eq></td>
                                <td width="130"><a href="#" class="btn_edit">编辑</a> 
                                	<a href="javascript:void(0)" rate="{$b.bid}" class="btn_del">删除</a></td>
                            </tr>
							</volist>
                        </table>
                    {$brand.html}     
            </div>
            <!-- GuanLianBrand结束 -->
    
            <div id="NewBrand">
                <h4 class="subtitle2">新增品牌</h4>
                <form action="" class="Searchform" method="post">
                品牌名称：<input name="txt" type="text" class="text search_key" /><button class="btn_send dosearch_brand"  type="button">搜索</button>
                </form>
            </div>
            <!-- NewBrand结束 -->
    
    
    		<div id="addBrand" style="display:none">
				<form action="{:U('Setting/add_brand')}" class="form" enctype="multipart/form-data" method="post" onSubmit="return check();"><p>
				对不起，没有搜索到相应的品牌，请手动添加！</p>
				<dl>
					<dt>品牌名称：</dt>
					<dd><input name="brand_name" type="text" class="text" /></dd>
					<dt>品牌标志：</dt>
					<dd>
						<input type="file" name="brand_ico" />
					</dd>
					<dt>品牌介绍：</dt>
					<dd><textarea name="brand_intro" cols="" rows=""></textarea></dd>
					<dd>
				 <button class="btn_send"  type="submit">提交</button></dd>
				</dl>
				</form>
            </div>
            <!-- addBrand结束 -->
            <script>
            function check(){
            	var file = $("input[name='brand_ico']").attr('value');
            	var name = $("input[name='brand_name']").attr('value');
            	if(name == ""){
            		alert('品牌名称是要写的哦！');
            		return false;
            	}
            	if(file == ""){
            		alert('别忘记上传品牌logo哦！');
            		return false;
            	}
            }
            </script>
            
            <div id="BrandList">
				<ul class="search_brand" style="display:none">
				</ul>
				<span class="clear"></span>
			</div>
            <!-- BrandList结束 -->
            
        </div>
        <!-- GuanLian结束 -->


	</div>
	<!-- neirong结束 -->


	<span class="clear"></span>
	<!-- 清除浮动 -->


</div>
<!-- container结束 -->
<script>
	$(document).ready(function(){
		$(".btn_del").click(function(){
			var con = confirm('确定取消关联该品牌吗？');
			if(con){
				var bid = $(this).attr('rate');
				$.post("__URL__/del_brand", { "bid": bid},
	               function(data){
	                if (data.status==1) {
	                  location.replace(location.href);  
	              	}
	               }, "json");
			}
		});
		$(".dosearch_brand").click(function(){
			key = $(".search_key").val();
			if(key ==""){
				alert('请输入搜索品牌名称');
				return false;
			}
			$.post('__URL__/search_brand',{key:key},function(res){
				if(!res){
					$("#addBrand").css('display','block');
					$(".search_brand").css('display','none');
				}else{
					$("#addBrand").css('display','none');
					var html = '';
					for(i=1;i<=res.length;i++){
						html = html + '<li><a href="javascript:void(0)" class="photo"><img src="'+res[i-1]['brand_ico']['url']+'" alt="图片描述" /></a><em>'+res[i-1]['brand_name']+'</em><a href="javascript:void(0)" rate="'+res[i-1]['bid']+'" class="btn_adds bind_brand">添加</a></li>';
					}
					$(".search_brand").html(html);
					$(".search_brand").css('display','block');
				}
			},'json');
		});
		$(".bind_brand").live('click',function(){
			element = $(this);
			bid = element.attr('rate');
			$.post('__URL__/bind_brand',{bid:bid},function(res){
				alert(res.info);
				if(res.status){
					element.parent().css('display','none');
					brand_name = element.parent().find("em").html();
					brand_img = element.parent().find("img").attr('src');
					newhtml = '<tr><td width="120">'+brand_name+'</td><td><a href="#"><img src="'+brand_img+'" alt="图片描述" /></a></td><td width="130"><a href="#" class="btn_edit">编辑</a><a href="#" class="btn_del">删除</a></td></tr>';
					oldhtml = $(".GWlist").html();
					$(".GWlist").html(oldhtml+newhtml);
					location.replace(location.href); 
				}
			},'json');
		});
	});
</script>
<include file="Public:bottom" />